package com.ssyt.ssh.sys.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssyt.ssh.sys.entity.BlogUser;
import com.ssyt.ssh.sys.service.BlogUserService;

@Controller
@RequestMapping("/sys")
public class BlogUserController {

	@Autowired
	private BlogUserService userService;

	@RequestMapping("/login")
	public String login(@RequestParam String username,
			@RequestParam String password, Model model) throws Exception {
		BlogUser user = userService.doLogin(username, password);
		System.out.println(user);
		if (user != null) {
			model.addAttribute("user", userService.doLogin(username, password));
			return "views/sys/backstage";
		} else {
			return "views/sys/main";
		}
	}
	@RequestMapping("/add")
	public String add(@RequestParam String code,
			@RequestParam String password, BlogUser blogUser) {
		System.out.println(code + "  " + password);
		blogUser.setCode(code);
		blogUser.setPassword(password);
		userService.add(blogUser);
		return "views/sys/backstage";
	}
	@ResponseBody
	@RequestMapping("/listUser")
	public List<BlogUser> listUser(){
		return userService.listUser();
	}
}
